normal_poll_source = ColumnDataSource( df[df["Poll_Type"]=="Normal Poll"] )
result_source = ColumnDataSource( df[df["Poll_Type"]=="Result"] )
exit_poll_source = ColumnDataSource( df[df["Poll_Type"]=="Exit Poll"] )
def VI_time_series(title,col,colour):
p = figure(x_axis_type="datetime",x_axis_label = "Fieldwork_Midpoint_Date",y_axis_label="%",
plot_width=600, plot_height=280, title=title,
tools='box_select,pan,wheel_zoom,box_zoom,reset', active_drag="box_select")
p.scatter('Fieldwork_Midpoint_Date', col, source=normal_poll_source, color=colour)
p.diamond('Fieldwork_Midpoint_Date', col, source=result_source, color=colour, size=40,fill_alpha=0.3,line_alpha=0.0)
p.x('Fieldwork_Midpoint_Date', col, source=exit_poll_source, color=colour, size=40,fill_alpha=0.3,line_alpha=0.3)
return p
# Conservatives
p1 = VI_time_series(title="Conservative (Voting Intention)",col="Con",colour='blue')
# Labour
p2 = VI_time_series(title="Labour (Voting Intention)",col="Lab",colour='red')
# Con-Lab
p3 = VI_time_series(title="Conservative lead over Labour (Voting Intention)",col="Con lead",colour='pink')
# LibDems
p4 = VI_time_series(title="LibDem (Voting Intention)",col="LD",colour='orange')
# UKIP
p5 = VI_time_series(title="UKIP (Voting Intention)",col="UKIP",colour='purple')
# Green
p6 = VI_time_series(title="Green (Voting Intention)",col="Green",colour='green')
# BNP
p7 = VI_time_series(title="BNP (Voting Intention)",col="BNP",colour='black')
# SDP
p8 = VI_time_series(title="SDP (Voting Intention)",col="SDP",colour='yellow')
# BXP
p9 = VI_time_series(title="BXP (Voting Intention)",col="BXP",colour='cyan')
# TIG/CUK
p10 = VI_time_series(title="TIG/CUK (Voting Intention)",col="TIG/CUK",colour='grey')
# TIG/CUK
p11 = VI_time_series(title="Referendum (Voting Intention)",col="Referendum",colour='purple')
# Link the x/y ranges
# okay - not the y-range, that makes LD invisible!
# p2.y_range = p1.y_range
# p3.y_range = p1.y_range
p2.x_range = p1.x_range
p3.x_range = p1.x_range
figs = [p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11]
for fig in figs[1:]:
fig.x_range = p1.x_range
layout = column(figs)
show(layout)